<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			#div01{
				width: 50px;
				height: 50px;
				position: absolute;
				background-color: lightblue;
			}
		</style>
	</head>
	<body>
		<div id="div01">			
		</div>
		
		<script type="text/javascript">
			var moving = false;
			var posX;
			var posY;
			div01.onmousedown = function(){
				console.log("鼠标按下")
				moving = true
				// 鼠标在块中的偏移
				posX = div01.offsetLeft - event.clientX;
				posY = div01.offsetTop - event.clientY;
			}
			div01.onmousemove = function(){
				console.log("鼠标移动")
				if(moving)
				{
					div01.style.left = event.clientX+posX + "px";
					div01.style.top = event.clientY+posY + "px";
				}
			}
			div01.onmouseup = function(){
				console.log("鼠标抬起")
				moving = false;
			}
		</script>
	</body>
</html>
